package com.youmu.sichuansfc.common;

import com.youmu.sichuansfc.enums.ResultEnum;
import lombok.Data;

import java.io.Serializable;

/**
 *  ajax 返回数据格式 公共类
 */
@Data
public class CommonRes implements Serializable {

    protected Integer status;

    protected String msg;

    protected Object data;

    public static CommonRes success(Object beans) {
        CommonRes commonRes = new CommonRes();
        commonRes.setData(beans);
        commonRes.setStatus(ResultEnum.SUCCESS.getStatus());
        commonRes.setMsg(ResultEnum.SUCCESS.getMessage());
        return commonRes;
    }

    public static CommonRes exception(ResultEnum resultEnum) {
        CommonRes commonRes = new CommonRes();
        commonRes.setStatus(resultEnum.getStatus());
        commonRes.setMsg(resultEnum.getMessage());
        return commonRes;
    }

    public static CommonRes success() {
        CommonRes commonRes = new CommonRes();
        commonRes.setStatus(ResultEnum.SUCCESS.getStatus());
        commonRes.setMsg(ResultEnum.SUCCESS.getMessage());
        return commonRes;
    }

    public static CommonRes fail() {
        CommonRes commonRes = new CommonRes();
        commonRes.setStatus(ResultEnum.FAIL.getStatus());
        commonRes.setMsg(ResultEnum.FAIL.getMessage());
        return commonRes;
    }

    public static CommonRes checkFail(String message) {
        CommonRes commonRes = new CommonRes();
        commonRes.setStatus(ResultEnum.FAIL.getStatus());
        commonRes.setMsg(message);
        return commonRes;
    }

}